home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / fstream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  10.0 KB  |  362 lines

  1. #ifndef __STD_FSTREAM__
  2. #define __STD_FSTREAM__
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * fstream -- Declarations for the Standard Library file bufs and streams
  8.  *
  9.  * $Id: fstream,v 1.48 1996/09/24 19:01:05 smithey Exp $
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  14.  * ALL RIGHTS RESERVED *
  15.  * The software and information contained herein are proprietary to, and
  16.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  17.  * intends to preserve as trade secrets such software and information.
  18.  * This software is furnished pursuant to a written license agreement and
  19.  * may be used, copied, transmitted, and stored only in accordance with
  20.  * the terms of such license and with the inclusion of the above copyright
  21.  * notice.  This software and information or any other copies thereof may
  22.  * not be provided or otherwise made available to any other person.
  23.  *
  24.  * Notwithstanding any other lease or license that may pertain to, or
  25.  * accompany the delivery of, this computer software and information, the
  26.  * rights of the Government regarding its use, reproduction and disclosure
  27.  * are as set forth in Section 52.227-19 of the FARS Computer
  28.  * Software-Restricted Rights clause.
  29.  * 
  30.  * Use, duplication, or disclosure by the Government is subject to
  31.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  32.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  33.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  34.  * P.O. Box 2328, Corvallis, Oregon 97339.
  35.  *
  36.  * This computer software and information is distributed with "restricted
  37.  * rights."  Use, duplication or disclosure is subject to restrictions as
  38.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  39.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  40.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  41.  * then the "Alternate III" clause applies.
  42.  *
  43.  **************************************************************************/
  44. #include <stdcomp.h>
  45.  
  46. #include <istream>
  47. #include <ostream>
  48. #include <streambuf>
  49.  
  50. #ifndef _RWSTD_NO_NEW_HEADER
  51. #include <cstdlib>
  52. #include <cfcntl>
  53. #else
  54. #include <stdlib.h>
  55. #include <fcntl.h>
  56. #endif
  57.  
  58.  
  59. #if defined (_MSC_VER) || defined (__TURBOC__)
  60. #include <io.h>
  61. #else
  62. #ifndef _RWSTD_NO_NEW_HEADER
  63. #include <cunistd>
  64. #else
  65. #include <unistd.h>
  66. #endif
  67.  
  68. #endif
  69.  
  70. #ifndef _RWSTD_NO_NAMESPACE
  71. namespace std {
  72. #endif  
  73.  
  74. extern int _RWSTDExport __rwOpenTable[32];
  75.  
  76. template<class charT, class traits>
  77. class _RWSTDExportTemplate basic_filebuf : public basic_streambuf<charT, traits> {
  78.  
  79.   private:
  80.  
  81.   #ifdef HPPA_WA
  82.   public:
  83.   #endif
  84.   
  85.     typedef basic_ios<charT, traits>              ios_type;
  86.     typedef _TYPENAME traits::state_type           state_t; 
  87.     
  88.   public:
  89.     typedef traits                       traits_type;
  90.     typedef charT                char_type;
  91.     typedef _TYPENAME traits::int_type    int_type;
  92.     typedef _TYPENAME traits::pos_type    pos_type;
  93.     typedef _TYPENAME traits::off_type    off_type;
  94.  
  95.     basic_filebuf();
  96.     basic_filebuf(int fd);
  97.  
  98.     virtual ~basic_filebuf();
  99.  
  100.     bool is_open() const;
  101.  
  102.     basic_filebuf<charT, traits> *
  103.       open(const char *s, ios_base::openmode, long protection = 0666 );
  104.  
  105.     basic_filebuf<charT, traits> *open(int fd);
  106.  
  107.     basic_filebuf<charT, traits> *close();
  108.  
  109.   protected:
  110.  
  111.     virtual int      showmanyc();
  112.     virtual int_type overflow(int_type c = traits::eof());
  113.     virtual int_type pbackfail(int_type c = traits::eof());
  114.     virtual int_type underflow();
  115.  
  116.     virtual basic_streambuf<charT,traits>* 
  117.                   setbuf(char_type *s,streamsize n);
  118.  
  119.  
  120.     virtual pos_type seekoff(off_type off,
  121.                              ios_base::seekdir way,
  122.                              ios_base::openmode which =
  123.                                        ios_base::in | ios_base::out);
  124.     virtual pos_type seekpos(pos_type sp,
  125.                              ios_base::openmode which =
  126.                                        ios_base::in | ios_base::out);
  127.  
  128.     virtual int sync( );
  129.  
  130.     virtual streamsize xsputn(const char_type *s, streamsize n);
  131.     
  132.  
  133.   private:
  134.  
  135.     int                     file_;
  136.     bool                        read_buff_;
  137.     bool             write_buff_;
  138.     streamsize             last_numb_read_;
  139.     streamsize            __rwBufferSize;
  140.  
  141.     streamsize                  absolute_pos;
  142.  
  143.     state_t                     *state_beg;
  144.     state_t                     *state_end;
  145.  
  146.     char_type                   *data_;
  147.  };
  148.  
  149.  
  150.  
  151. template<class charT, class traits>
  152. class _RWSTDExportTemplate basic_ifstream : public basic_istream<charT, traits> {
  153.  
  154.   public:
  155.  
  156.     typedef basic_ios<charT, traits>                   ios_type;
  157.  
  158.     typedef traits                            traits_type;
  159.     typedef charT                         char_type;
  160.     typedef _TYPENAME traits::int_type         int_type;
  161.     typedef _TYPENAME traits::pos_type         pos_type;
  162.     typedef _TYPENAME traits::off_type         off_type;
  163.     
  164.   public:
  165.  
  166.     basic_ifstream();
  167.      
  168.     _EXPLICIT basic_ifstream(const char *s, 
  169.                             ios_base::openmode mode = ios_base::in,
  170.                             long protection = 0666 );
  171.  
  172.     _EXPLICIT basic_ifstream(int fd);
  173.  
  174.     basic_ifstream(int fd, char_type *buf, int len);
  175.  
  176.     virtual ~basic_ifstream();
  177.  
  178.     basic_filebuf<charT, traits> *rdbuf() const;
  179.  
  180.     bool is_open();
  181.  
  182.     void open(const char *s, ios_base::openmode mode = ios_base::in,
  183.               long protection = 0666 );
  184.  
  185.     void close();
  186.  
  187.   protected:
  188.  
  189.   private:
  190.  
  191.     basic_filebuf<charT, traits>              fb_;
  192.  
  193.    
  194. };
  195.  
  196.  
  197. template<class charT, class traits>
  198. class _RWSTDExportTemplate basic_ofstream : public basic_ostream<charT, traits> {
  199.  
  200.   public:
  201.  
  202.     typedef basic_ios<charT, traits>                   ios_type;
  203.  
  204.     typedef traits                                     traits_type;
  205.     typedef charT                               char_type;
  206.     typedef _TYPENAME traits::int_type                  int_type;
  207.     typedef _TYPENAME traits::pos_type                  pos_type;
  208.     typedef _TYPENAME traits::off_type                  off_type;
  209.  
  210.   public:
  211.  
  212.     basic_ofstream();
  213.      
  214.     _EXPLICIT basic_ofstream(const char *s, ios_base::openmode mode =
  215.                             ios_base::out,
  216.                             long protection = 0666 );
  217.  
  218.     _EXPLICIT basic_ofstream(int fd);
  219.  
  220.     basic_ofstream(int fd, char_type *buf, int len);
  221.  
  222.     virtual ~basic_ofstream();
  223.  
  224.     basic_filebuf<charT, traits> *rdbuf() const;
  225.  
  226.     bool is_open();
  227.  
  228.      
  229.     void open(const char *s, ios_base::openmode mode = 
  230.               ios_base::out,
  231.               long protection = 0666 );
  232.      
  233.     void close();
  234.  
  235.   protected:
  236.  
  237.   private:
  238.  
  239.     basic_filebuf<charT, traits>              fb_;
  240.  };
  241.  
  242. /*
  243.  *
  244.  *  Class basic_fstream
  245.  *
  246.  */
  247.  
  248. template<class charT, class traits>
  249. class _RWSTDExportTemplate basic_fstream : public basic_iostream<charT, traits> {
  250.  
  251.   public:
  252.  
  253.     typedef basic_ios<charT, traits>          ios_type;
  254.  
  255.     typedef traits                            traits_type; 
  256.     typedef charT                         char_type;
  257.     typedef _TYPENAME traits::int_type         int_type;
  258.     typedef _TYPENAME traits::pos_type         pos_type;
  259.     typedef _TYPENAME traits::off_type         off_type;
  260.     
  261.  
  262.     basic_fstream();
  263.       
  264.     _EXPLICIT basic_fstream(const char *s, ios_base::openmode mode = 
  265.                            ios_base::in | ios_base::out, 
  266.                            long protection= 0666 );
  267.  
  268.     _EXPLICIT basic_fstream(int fd);
  269.  
  270.     basic_fstream(int fd, char_type *buf, int len);
  271.  
  272.     virtual ~basic_fstream();
  273.  
  274.     basic_filebuf<charT, traits> *rdbuf() const;
  275.  
  276.     bool is_open();
  277.  
  278.     void open(const char *s, ios_base::openmode mode = 
  279.               ios_base::in | ios_base::out, 
  280.               long protection = 0666 );
  281.  
  282.     void close();
  283.  
  284.   protected:
  285.  
  286.   private:
  287.  
  288.     basic_filebuf<charT, traits>              fb_;
  289.  
  290.  };
  291.  
  292.  
  293. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  294. typedef basic_filebuf<char>                            filebuf;
  295. #else
  296. typedef basic_filebuf<char, char_traits<char> >         filebuf;
  297. #endif
  298. #ifndef _RWSTD_NO_WIDE_CHAR
  299. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  300. typedef basic_filebuf<wchar_t>                         wfilebuf;
  301. #else
  302. typedef basic_filebuf<wchar_t, char_traits<wchar_t> >   wfilebuf;
  303. #endif
  304. #endif
  305.  
  306.  
  307. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  308. typedef basic_ifstream<char>                           ifstream;
  309. #else
  310. typedef basic_ifstream<char, char_traits<char> >        ifstream;
  311. #endif
  312.  
  313. #ifndef _RWSTD_NO_WIDE_CHAR
  314. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  315. typedef basic_ifstream<wchar_t>                        wifstream;
  316. #else
  317. typedef basic_ifstream<wchar_t, char_traits<wchar_t> >  wifstream;
  318. #endif
  319. #endif
  320.  
  321.  
  322. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  323. typedef basic_ofstream<char>                           ofstream;
  324. #else
  325. typedef basic_ofstream<char, char_traits<char> >        ofstream;
  326. #endif
  327. #ifndef _RWSTD_NO_WIDE_CHAR
  328. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  329. typedef basic_ofstream<wchar_t>                        wofstream;
  330. #else
  331. typedef basic_ofstream<wchar_t, char_traits<wchar_t> >  wofstream;
  332. #endif
  333. #endif
  334.  
  335. #ifndef _RWSTD_NO_DEFAULT_TEMPLATES
  336. typedef basic_fstream<char>                           fstream;
  337. #else
  338. typedef basic_fstream<char, char_traits<char> >        fstream;
  339. #endif
  340.  
  341. #ifndef _RWSTD_NO_WIDE_CHAR
  342. #ifndef _RWSTD_NO_DEFAULT_TEMPLATES
  343. typedef basic_fstream<wchar_t>                        wfstream;
  344. #else
  345. typedef basic_fstream<wchar_t, char_traits<wchar_t> >  wfstream;
  346. #endif
  347. #endif
  348.  
  349. #ifndef _RWSTD_NO_NAMESPACE
  350. }
  351. #endif
  352.  
  353. #ifdef _RWSTD_COMPILE_INSTANTIATE
  354. #include <fstream.cc>
  355. #endif
  356. #ifndef __USE_STD_NAMES__
  357.   using namespace std;
  358. #endif
  359.  
  360. #pragma option pop
  361. #endif /* __FSTREAM__ */
  362.